int max(int x,int y) { return x>y?x:y; } double max(double x,double y) { return x>y?x:y; }
template<class T> T max(T x,T,y) { return x>y?x:y; }
You need to enable Javascript in your browser to edit pages.
help on how to format text
template
当我们实现函数重载的时候,一般的方法会需要很繁杂的编程,相同规格的代码需要一遍又一遍的Writing:such as:
int max(int x,int y) { return x>y?x:y; } double max(double x,double y) { return x>y?x:y; }如果使用模板就比较简单了:template<class T> T max(T x,T,y) { return x>y?x:y; }这样一步就够了,是不是很简单。